package com.tanhua.management.controller;

import com.tanhua.management.service.ManageVideoService;
import com.tanhua.management.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author why
 */
@RestController
@RequestMapping("management/manage/videos")
public class ManageVideoController {

    @Autowired
    private ManageVideoService manageVideoService;

    /**
     *
     * @param page    当前页
     * @param pageSize  尺寸
     * @param sortProp  排序字段
     * @param sortOrder ascending 升序 descending 降序
     * @param uid   用户id
     * @return
     */
    @GetMapping
    public ResponseEntity<PageResult> queryVideoByUid(@RequestParam(value = "page",defaultValue = "1") Integer page
                                                      ,@RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                                                      @RequestParam("sortProp") String sortProp,
                                                      @RequestParam("sortOrder") String sortOrder,
                                                      @RequestParam("uid") String uid)
    {

        try {
            PageResult pageResult =this.manageVideoService.queryVideoByUid(page,pageSize,sortProp,sortOrder,uid);

            if (pageResult!=null){
                return ResponseEntity.ok(pageResult);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
